<?php

use yii\db\Migration;

/**
 * Handles the creation of table `sdb_user`.
 */
class m201105_092013_create_sdb_user_table extends Migration
{
    private $tableName = "sdb_user";

    public function up()
    {
        $tableOptions = "CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB COMMENT '用户表'";

        $this->createTable($this->tableName,[
            'id' => $this->primaryKey()->comment('主键'),
            'user_name' => $this->string(150)->notNull()->defaultValue('')->comment('用户名'),
            'password' => $this->string(150)->notNull()->defaultValue('')->comment('密码'),
            'nickname' => $this->string(150)->notNull()->defaultValue('')->comment('密码'),
            'create_time' => $this->timestamp()->notNull()->defaultExpression('CURRENT_TIMESTAMP')->comment('创建时间'),
            'update_time' => $this->timestamp()->notNull()->defaultExpression('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')->comment('更新时间'),
        ],$tableOptions);

        //添加唯一索引
        $this->createIndex('pk_user_name',$this->tableName,'user_name');
        //$this->createIndex('idx_user_name',$this->tableName,'user_name');
    }

    public function down()
    {
        $this->dropTable($this->tableName);
    }
}
